package a07_二叉树;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * <p>
 * a16_找树左下角的值复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/11
 */
public class a16_找树左下角的值复习3 {
    //最底层，最左边
    //中左右
    public int findBottomLeftValue(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);

        int result = 0;
        while (!queue.isEmpty()){
            int size = queue.size();
            result = queue.peek().val;
            while (size > 0) {
                TreeNode poll = queue.poll();
                if(poll.left != null){
                    queue.add(poll.left);
                }
                if(poll.right != null){
                    queue.add(poll.right);
                }
                size--;
            }
        }
        return result;
    }
}
